﻿using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Customers.Core;
using Webshop20.Domain.Security.Authentication.Core;

namespace Webshop20.UnitTests.Builder
{
    public class BuildAccount
    {
        private int? accountId = 1;
        private Customer customer = new BuildCustomer();
        private string password = "xxxxxx";
        private string passwordConfirm = "xxxxxx";
        private ControllQuestion controlQuestion = new ControllQuestion("Name of your dog?");
        private string controlAnswer = "Fifi";
        private string loginName = "Max";

        private IConstraintSet<Account> accountConstraintSet;  

        public BuildAccount()
        {
            accountConstraintSet = new BuildConstraintSet<Account>()
                .WithInvariantValidation(true, new Account())
                .Build();
        }


        private Account Build()
        {
            return new Account(loginName, password,passwordConfirm, controlQuestion, controlAnswer);
        }

        public BuildAccount WithPassword(string pwd)
        {
            password = pwd;
            return this;
        }

        public BuildAccount WithLoginName(string loginName)
        {
            this.loginName = loginName;
            return this;
        }

        public BuildAccount WithPasswordConfirm(string pwd)
        {
            passwordConfirm = pwd;
            return this;
        }

        public BuildAccount WithConstraintSet(IConstraintSet<Account> set)
        {
            this.accountConstraintSet = set;
            return this;
        }

        public BuildAccount WithCustomer(Customer customer)
        {
            this.customer = customer;
            return this;
        }

        public static implicit operator Account(BuildAccount builder)
        {
            return builder.Build();
        } 
    }
}